<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <style type="text/css">

    </style>
</head>
<body>
<div class="page-return">
    <div class="ops-form">
        <div class="page-head">
            <form class="form-horizontal tasi-form" method="post" id="params" action="">
                <div class="form-group">
                    <label class="col-sm-1 control-label">手机号码</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" name="phoneNumber" id="phoneNumber" value="">
                    </div>
                    <label class="col-sm-1 control-label">身份证号</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" name="idCardNumber" id="idCardNumber" value="">
                    </div>
                    <div class="col-sm-3">
                        <button type="button" class="btn btn-info" onclick="">搜索</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="ops-table" >
        <caption>
            <div class="ops-edit">
                <button type="button" class="btn btn-info" id="${entityFirstLowerName}AddBtn">新增</button>
                <button type="button" class="btn btn-info" id="${entityFirstLowerName}UpdateBtn">修改</button>
                <button type="button" class="btn btn-info" id="${entityFirstLowerName}DeleteBtn">删除</button>
            </div>
        </caption>
        <div class="ops-table-content">
            <table id="${entityFirstLowerName}Table"></table>
        </div>
    </div>
</div>
</body>
<script>
    $(function(){
        var ${entityFirstLowerName}Table = $("#${entityFirstLowerName}Table").bootstrapTable({ // 对应table标签的id
            url: "${entityFirstLowerName}/listData${entityName}ByParam", // 获取表格数据的url
            queryParams: function (params) { // 请求服务器数据时发送的参数，可以在这里添加额外的查询参数，返回false则终止请求
                var paramOption = {
                    pageSize: params.limit, // 每页要显示的数据条数
                    pageNumber: (params.offset/params.limit)+1, // 每页显示数据的开始行号
                    sortName: params.sort, // 要排序的字段
                    searchText:'',//搜索内容
                    sortOrder: params.order, // 排序规则
                    dataId: $("#dataId").val() // 额外添加的参数
                }
                return paramOption;
            },
            columns: [
                {
                    checkbox: true // 显示一个勾选框
                },<#list columnMap as column>{
                    field: '${column.attrEnName}',
                    title: '${column.attrChName}',
                    align: 'center',
                    valign: 'middle',
                    halign:'center'
                },</#list>{
                    title: "操作",
                    width: 60, // 定义列的宽度，单位为像素px
                    formatter: function (value, row, index) {
                        return '<button class="btn btn-primary btn-sm" onclick="del(\'' + row.stdId + '\')">删除</button>';
                    }
                }
            ]
        });
        $("#${entityFirstLowerName}AddBtn").click(function () {
            layer.open({
                type: 2,
                title: '新增数据',
                shadeClose: true,
                shade: false,
                area: ['780px', '480px'],
                content: '/views/${entityLowerName}/${entityLowerName}_form.jsp'
            });
        });
        $("#${entityFirstLowerName}UpdateBtn").click(function () {
            var idArray = $(${entityFirstLowerName}Table).bootstrapTable('getSelections');
            if(idArray.length > 1){
                layer.msg('每次只能修改一条记录', function(){});
                return false;
            }
            if(idArray.length < 1){
                layer.msg('请选择一条记录进行修改', function(){});
                return false;
            }
            var ${entityFirstLowerName}Id = idArray[0].id;
            layer.open({
                type: 2,
                title: '修改数据',
                shadeClose: true,
                shade: false,
                area: ['780px', '480px'],
                content: '/${entityFirstLowerName}/select${entityName}ById?${entityFirstLowerName}Id='+${entityFirstLowerName}Id
            });
        });
        $("#${entityFirstLowerName}DeleteBtn").click(function () {
            var objArray = ${entityFirstLowerName}Table.bootstrapTable('getSelections');
            if(objArray.length < 1){
                layer.msg('请选择至少一条记录进行删除', function(){});
                return false;
            }
            var idArray = [];
            for (i = 0; i < objArray.length; i++) {
                idArray[i] = objArray[i].id;
            }
            layer.confirm('你确定要删除', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    type:"get",
                    url:'/${entityFirstLowerName}/remove${entityName}?idArray='+idArray.join(','),
                    dataType:"json",
                    success:function(data){
                        if(data.resCode == '200'){
                            parent.$("#${entityFirstLowerName}Table").bootstrapTable('refresh',{silent: true});
                            parent.layer.msg(data.resMessage,{time:1200});
                            return true;
                        }else {
                            parent.layer.msg(data.resMessage);
                            return false;
                        }
                    },
                    error:function(data){
                        parent.layer.msg("错误："+data.resMessage);
                    }
                })
            }, function(){
                layer.msg('取消操作', {
                    time: 1500 //1.5s后自动关闭
                });
            });
        });
    })
</script>
</html>